<template>
  <div>
    <zm-dialog :title="'审批'+dialogTitle" :visible.sync="value" append-to-body size="small" :before-close="dialogClose" :close-on-click-modal="false">
      <zm-form :model="form" ref="zmForm" :rules="rules">
        <div class="mb20">{{reasonParams.type === 'refuse' ? '否决订单，需要填写否决原因':'通过审批，需要填写通过原因'}}</div>
        <zm-form-item prop="remark">
          <zm-input v-model="form.remark" type="textarea" :maxlength="300" :placeholder="`请输入审批${dialogTitle}原因`"></zm-input>
        </zm-form-item>
      </zm-form>
      <div slot="footer" class="tr">
        <zm-button @click="dialogClose" type="">取消</zm-button>
        <zm-button @click="save" type="primary">完成</zm-button>
      </div>
    </zm-dialog>
  </div>
</template>

<script>
import dialogMixin from '@/mixins/dialogMixin'
import approveProcessApis from '@/api/src/approve'

export default {
  mixins: [dialogMixin],
  props: {
    reasonParams: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  data () {
    return {
      form: {
        remark: ''
      },
      rules: {
        remark: [
          {
            required: true,
            message: '请输入原因',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  computed: {
    dialogTitle () {
      return this.reasonParams.type === 'refuse' ? '' : '通过'
    }
  },
  methods: {
    async save () {
      let _valid = false
      this.$refs.zmForm.validate(valid => {
        _valid = valid
      })
      if (!_valid) return
      this.$emit('after-reason', this.form)
    }
  }

}
</script>
